<template>
    <div class="app-container content-wrapper">
        <div class="filter-container">
            <el-form :model="listQuery" :inline="true" ref="filterForm" style="display: inline-block">
                <el-form-item class="filter-item">
                    {{$route.params.carnum}}
                </el-form-item>
            </el-form>
        </div>

        <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row style="width: 100%">

            <el-table-column label="ID" width="85" align="center" fixed="left">
                <template slot-scope="scope"> {{scope.row.id}} </template>
            </el-table-column>

            <el-table-column label="车牌号" align="center" fixed="left" width="120px">
                <template slot-scope="scope"> {{scope.row.carFullNum}} </template>
            </el-table-column>

            <el-table-column label="类型" align="center" fixed="left">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.wx">无伤</el-tag>
                    <el-tag type="danger" v-else="">新伤</el-tag>
                </template>
            </el-table-column>

            <el-table-column label="轮胎" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c1 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="外观" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c2 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="灯光" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c3 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="喇叭" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c4 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="雨刮" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c5 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="内饰" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c6 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="发动机" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c7 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="机油" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c8 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="刹车油" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c9 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="水箱水" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c10 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="雨刮水" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c11 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="备胎" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c12 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="标贴" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c13 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="三脚架" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c14 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="千斤顶" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c15 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="行驶证" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c16 === 1">正常</el-tag>
                    <el-tag type="danger" v-else="">异常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="是否已加油" align="center" width="130">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c17 === 1">是</el-tag>
                    <el-tag type="danger" v-else="">否</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="地点" align="center" width="200">
                <template slot-scope="scope">
                    {{scope.row.point}}
                </template>
            </el-table-column>
            <el-table-column label="里程数" align="center" width="150">
                <template slot-scope="scope">
                   {{scope.row.mileage}}
                </template>
            </el-table-column>
            <el-table-column label="油量情况" align="center" width="100">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.c18 === 1">满油</el-tag>
                    <el-tag type="success" v-else-if="scope.row.c18 === 2">3/4以上</el-tag>
                    <el-tag type="warning" v-else-if="scope.row.c18 === 3">1/2~3/4</el-tag>
                    <el-tag type="danger" v-else-if="scope.row.c18 === 4">1/4~1/2,5</el-tag>
                    <el-tag type="danger" v-else="">1/4以下</el-tag>
                </template>
            </el-table-column>

            <el-table-column label="备注" align="center" width="200">
                <template slot-scope="scope"> {{scope.row.remarks}} </template>
            </el-table-column>
            <el-table-column label="上传人" align="center" fixed="right">
                <template slot-scope="scope"> {{scope.row.userName}} </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" fixed="right" width="180">
                <template slot-scope="scope"> {{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}} </template>
            </el-table-column>

            <el-table-column label="操作" width="120px" align="center" fixed="right">
                <template slot-scope="scope">
                    <el-button size="small" type="danger" icon="delete" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>

        </el-table>

        <div v-show="!listLoading" class="pagination-container">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="listQuery.page"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="listQuery.rows"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>


    </div>
</template>

<script>
    import fetch from '@/utils/fetch'
    import { created, deleted, updated, fetchObject, fetchList } from '@/api/tukuan/check'

    export default {
        name: 'app',
        data() {
            return {
                list: null,
                total: null,
                listLoading: true,
                listQuery: {
                    page: 1,
                    rows: 10,
                    carId: this.$route.params.carId,
                    carName: undefined,
                    orderBy: 'create_time desc'
                }

            }
        },
        created() {
            this.getList()
        },
        filters: {
            statusFilter(status) {
                const statusArray = ['正常', '锁定']
                return statusArray[status?--status:'']
            },
            statusTagFilter(status) {
                const statusArray = ['success', 'danger']
                return statusArray[status?--status:'']
            }
        },
        methods: {
            getList() {
                this.listLoading = true
                fetchList(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.total = response.data.total
                    this.listLoading = false
                }).catch((error)=>{
                    console.log(error)
                    this.listLoading = false
                })
            },
            handleSizeChange(val) {
                this.listQuery.rows = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleDelete(row) {
                this.$confirm('确定要删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleted(row.id).then(response => {
                        if(response.data.status) {
                            this.$notify({
                                title: '成功', message: response.data.message,
                                type: 'success', duration: 2000
                            })
                            this.getList()
                        } else {
                            this.$notify({
                                title: '发生错误', message: response.data.message,
                                type: 'error', duration: 2000
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '已取消删除' })
                })
            }
        }
    }
</script>

<!-- 局部样式 -->
<style rel="stylesheet/scss" lang="scss" scoped>

</style>